import { Request, Response } from 'express';

/** 延时 */
const waitTime = async (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export default {
  'GET /api/menu': async (req: Request, rep: Response) => {
    waitTime(1000);
    let query = req.query as API.MenuDataItem;
    let routes = [
      {
        id: 'bd6c4a4e-10fe-4bfb-b4a6-72ae30e68c42',
        name: '用户',
        path: '/user',
        icon: 'UserOutlined',
        routes: [
          { name: 'a', path: '/user/a' },
          { name: 'b', path: '/user/b' },
          { name: 'c', path: '/user/c' },
        ],
      },
      {
        id: 'a94663ce-9418-4540-a531-21fcdf9d6712',
        name: '菜单',
        path: '/menu',
        icon: 'MenuOutlined',
      },
    ];

    if (!query.parentId || query.parentId !== '-') {
      rep.status(200).send({
        success: true,
        total: 5,
        data: [
          {
            id: 'bd6c4a4e-10fe-4bfb-b4a6-72ae30e68c42',
            name: '用户',
            path: '/user',
            icon: 'UserOutlined',
          },
          {
            id: 'a94663ce-9418-4540-a531-21fcdf9d6712',
            name: '菜单',
            path: '/menu',
            icon: 'MenuOutlined',
          },
          {
            id: '81fcb1d9-1f75-4e05-8a4e-b060f3f45445',
            name: 'a',
            path: '/user/a',
            parentId: 'bd6c4a4e-10fe-4bfb-b4a6-72ae30e68c42',
          },
          {
            id: 'ea66cd59-593a-445d-aa23-9f9314479c13',
            name: 'b',
            path: '/user/b',
            parentId: 'bd6c4a4e-10fe-4bfb-b4a6-72ae30e68c42',
          },
          {
            id: '9add1cb4-e736-449f-a513-6e7459c78cf8',
            name: 'c',
            path: '/user/c',
            parentId: 'bd6c4a4e-10fe-4bfb-b4a6-72ae30e68c42',
          },
        ],
      } as API.ResponsePagerMenuDataItem);
      return;
    }
    rep.status(200).send({
      success: true,
      data: routes,
    } as API.ResponsePagerMenuDataItem);
  },
};
